<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index(){
		
	}
	
	public function login(){
		$this->display();
	}
	
	//登录操作
	public function login_do(){
		
		$User				= D('User','Logic');
		if (!$User->create(I('get.'),4)){
			$this->error($User->getError());
		}	
		else{
			$row				= S(I('get.username').md5(I('get.password')));
			$User->id			= $row['id'];
			$User->before_ip	= $row['last_ip'];
			$User->last_ip		= get_client_ip();
			$User->login_time	= time();
			$User->save();
			$this->user_session_save($row);
			$this->success('登录成功', __APP__.'/Admin/index/welcome');
		}
	}	

	//登录session操作
	protected function user_session_save($data){
		
		session('id'		,$data['id']); 
		session('username'	,$data['username']); 
		session('role_id'	,$data['role_id']); 
		session('last_ip'	,$data['last_ip']); 
	}

	//注销操作
	public function login_out_do(){
		
		session(null);
		cookie(null);
		$this->success('已退出登录', __APP__.'/Admin/login/login');
	}
	
}